<?php
App::uses('AppModel', 'Model');
App::uses('AuthComponent', 'Controller/Component');

class Product extends AppModel {
	public $primaryKey = 'product_id';
	public function findAllData(){
		return $this->find("all");
	}

	/**
	* Get product lastest by category_id
	* @author ThanhTran
	* @since 2014-11-25
	* @return products
	*/
	public function findLastestById($id){
		return $this->find('all',array(
			'conditions' => array('shop_id' => $id, 'product_new'=>1),
			'order' => array('created_at' => 'desc'),
			'limit' =>6
			));
	}
	/**
	 * find all by shop id
	 */
	public function findAllLastestById($id){
		return $this->find('all',array(
			'conditions' => array('shop_id' => $id,'product_new'=>1),
			'order' => array('created_at' => 'desc')
			));
	}
	/**
	* Get best product by shop_id
	* @author ThanhTran
	* @since 2014-11-25
	* @return products
	*/
	public function findBestProduct($id){
		return $this->find('all',array(
			'conditions' => array('shop_id' => $id, 'best_sell'=>2),
			'order' => array('created_at' => 'desc'),
			'limit' =>6
			));
	}
	/**
	 * find all by shop id
	 */
	public function findAllBestProduct($id){
		return $this->find('all',array(
			'conditions' => array('shop_id' => $id,'best_sell'=>2),
			'order' => array('created_at' => 'desc')
			));
	}
	public function findById($id){
		return $this->find('first',array(
			'conditions' => array('product_id' => $id)
			));
	}
	/**
	 * find selling product
	 */
	public function findSellingProduct($shop_id,$category_id){
		return $this->find('all',array(
			'conditions' => array('shop_id' => $shop_id,'category_id' =>$category_id, 'provide'=>1),
			'order' => array('created_at' => 'desc')
			));
	}
	/**
	 * find selling product
	 */
	public function findStockProduct($shop_id,$category_id){
		return $this->find('all',array(
			'conditions' => array('shop_id' => $shop_id,'category_id' =>$category_id, 'provide'=>2),
			'order' => array('created_at' => 'desc')
			));
	}
	/**
	 * find by productId , shopId, created_by
	 */
	public function findByConditions($productId, $shopId, $accountId){
		return $this->find('first',array(
			'conditions' => array('product_id' =>$productId, 'shop_id' => $shopId, 'created_by'=>$accountId)
			));
	}
	
}
?>
